<!--车辆管理-->
<template>
	<el-card>
		<el-form :inline="true" :model="state.queryForm" @keyup.enter="getDataList()">
			<el-form-item class="form-button-right">
				<el-button v-auth="'module:car:save'" type="primary" @click="addOrUpdateHandle()">新增车辆</el-button>
				<el-button v-auth="'module:car:delete'" type="danger" @click="deleteBatchHandle()">批量删除</el-button>
			</el-form-item>

			<el-form-item>
				<el-select v-model="state.queryForm.stateId" placeholder="车辆状态"></el-select>
			</el-form-item>
			<el-form-item>
				<KeyQuery v-model="state.queryForm.keyword" @getDataList="getDataList()" />
			</el-form-item>
		</el-form>

		<el-row>
			<el-col :span="4">
				<DictTreeList ref="dictTreeListRef" v-model="state.queryForm.typeId" :code="dictCode" :title="'车辆分类'" :label="'分类名称'"></DictTreeList>
			</el-col>
			<el-col :span="20">
				<el-table v-loading="state.dataListLoading" :data="state.dataList" border style="width: 100%" @selection-change="selectionChangeHandle">
					<el-table-column type="selection" header-align="center" align="center" width="50"></el-table-column>
					<el-table-column prop="id" label="主键" header-align="center" align="center" v-if="false"></el-table-column>

					<el-table-column prop="imgUrl" label="车辆图片" header-align="center" align="center"></el-table-column>
					<el-table-column prop="name" label="车辆名称" header-align="center" align="center"></el-table-column>
					<el-table-column prop="plateNumber" label="车牌号" header-align="center" align="center"></el-table-column>
					<el-table-column prop="carTypeId" label="车型" header-align="center" align="center"></el-table-column>
					<el-table-column prop="modelStr" label="品牌型号" header-align="center" align="center"></el-table-column>

					<el-table-column prop="carPrice" label="裸车价" header-align="center" align="center"></el-table-column>
					<el-table-column prop="saddleNumberStr" label="车座" header-align="center" align="center"></el-table-column>
					<el-table-column prop="isStatr" label="车辆状态" header-align="center" align="center"></el-table-column>

					<el-table-column label="操作" fixed="right" header-align="center" align="center" width="150">
						<template #default="scope">
							<el-button v-auth="'module:car:update'" type="primary" link @click="addOrUpdateHandle(scope.row.id)">修改</el-button>
							<el-button v-auth="'module:car:delete'" type="primary" link @click="deleteBatchHandle(scope.row.id)">删除</el-button>
						</template>
					</el-table-column>
				</el-table>
				<el-pagination
					:current-page="state.page"
					:page-sizes="state.pageSizes"
					:page-size="state.limit"
					:total="state.total"
					layout="total, sizes, prev, pager, next, jumper"
					@size-change="sizeChangeHandle"
					@current-change="currentChangeHandle"
				>
				</el-pagination>
			</el-col>
		</el-row>

		<!-- 弹窗, 新增 / 修改 -->
		<add-or-update ref="addOrUpdateRef" @refreshDataList="getDataList" :code="dictCode"></add-or-update>
	</el-card>
</template>

<script setup lang="ts" name="ModuleCarIndex">
import { useCrud } from '@/hooks'
import { reactive, ref } from 'vue'
import { IHooksOptions } from '@/hooks/interface'
import DictTreeList from '@/views/nb_module/tree/dict-tree-list.vue'

import AddOrUpdate from './plane/car-a-u.vue'

const dictCode = 'CheLiangFenLei'

const state: IHooksOptions = reactive({
	dataListUrl: '/nb/car/page',
	deleteUrl: '/nb/car/delete',
	queryForm: {}
})

const addOrUpdateRef = ref()
const addOrUpdateHandle = (id?: number) => {
	addOrUpdateRef.value.init(id)
}

const { getDataList, selectionChangeHandle, sizeChangeHandle, currentChangeHandle, deleteBatchHandle } = useCrud(state)
</script>
